var webmessage=null;;
var ad=null;;
$(function(){
	BindtoupiaoCheckBox();
	bindtab();
	webmessage = new messagelist("newslist");
	ad = new messagelist("adlist");
	bindRegedit();
});



function BindtoupiaoCheckBox(){
	$("#radioOrChecked li a").click(function(){
		var inputs = $("#radioOrChecked li input");
		var checked = "";
		for(var i=0;i< inputs.length;i++){
			$input = $(inputs[i]);
			if($input.attr("checked")){
				checked+=$input.val()+",";	
			}
		}
		checked=checked.substring(0,checked.length-1);
		alert(checked);
		$("#online").load("checkList.html","",function(data){
			if(data!="nodata"){
				BindtoupiaoCheckBox();
			}
		})
	});
}

function bindtab(){ 
	$("#tab li").click(function(){
		var $li = $(this);
		var $sli = $li.siblings();
		var c = $li.attr("tabcontent");
		var lis = $("#tab li");
		for(var i=0;i<lis.length;i++){
			var $lii = $(lis[i]);
			$lii.removeClass("on");
		}
		$li.addClass("on");
		if(c=="online"){
			$("#online").css("display","block");
			$("#webmessage").css("display","none");
			$("#adlink").css("display","none");ad.stop();webmessage.stop();
			
		}else if(c=="webmessage"){
			$("#online").css("display","none");
			$("#webmessage").css("display","block");
			$("#adlink").css("display","none");
			webmessage.start();
			ad.stop();
		}else{
			$("#adlink").css("display","block");		
			$("#online").css("display","none");
			$("#webmessage").css("display","none");
			ad.start();
			webmessage.stop();
		}
		
		
	});
}

function messagelist(id){
	var lis = $("#"+id+" li");
	this.id=id;
	this.count = lis.length;
	
	var page = parseInt(this.count/8);
	
	if(this.count<=8){
		page=1;
	}else{
		if(this.count%8!=0){
				page++;
		}		
	}
	
	this.lisArray = [];
	var temparray=[];
	this.current=-1;
	var temp = 0;
	for(var i=0;i<page;i++){ 
		var t = 0;
		var cut = [];
		if(i+1>=page){
			cut=lis.slice(temp);
		}else{
			cut=lis.slice(temp,8);
			temp+=8;
		}
		this.lisArray.push(cut);
	}
}

messagelist.prototype={
	reload:function(){
		if(this.current>=0){
			for(var i=0;i<this.lisArray[this.current].length;i++){
				$(this.lisArray[this.current][i]).css("display","none");
			}
		}
		this.current++;
		if(this.current>=this.lisArray.length){
			this.current=0;
		}
		for(var i=0;i<this.lisArray[this.current].length;i++){
			$(this.lisArray[this.current][i]).css("display","block");
		}		
	},
	start:function(){
		this.current=-1;
		this.reload();
		var temp = this;
		this.interval = setInterval(function(){
			temp.reload();
		},5000);		
	},
	stop:function(){
		clearInterval(this.interval);
		$("#"+this.id+" li").css("display","none");
		
	}
	
}




